<html>
  <head>
    <script type="importmap">
      {
        "imports": {
          "../src/postData.js": "./mocks/postData.js"
        }
      }
    </script>
  </head>

  <body>
    <script type="module">
      import { runTests } from '@web/test-runner-mocha';
      import { expect } from '@esm-bundle/chai';
      import { sendMessage } from '../src/sendMessage.js';
      import { postData, __postDataSpy, __importMeta } from '../src/postData.js';

      runTests(() => {
        describe('sendMessage()', () => {
          beforeEach(() => {
            __postDataSpy.reset();
          });

          it('serves a mocked module', () => {
            expect(new URL(__importMeta.url).pathname).to.equal(
              '/packages/dev-server-import-maps/test-browser/test/mocks/postData.js',
            );
          });

          it('calls postData with message a', async () => {
            await sendMessage('a');
            expect(__postDataSpy.callCount).to.equal(1);
            expect(__postDataSpy.getCall(0).args).to.eql(['message', { message: 'a' }]);
          });

          it('calls postData with message b', async () => {
            await sendMessage('b');
            expect(__postDataSpy.callCount).to.equal(1);
            expect(__postDataSpy.getCall(0).args).to.eql(['message', { message: 'b' }]);
          });
        });
      });
    </script>
  </body>
</html>
